package com.example.trackcircuitdiagnosis.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.trackcircuitdiagnosis.entity.NormalDataEntity;
import com.example.trackcircuitdiagnosis.service.NormalDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@CrossOrigin
@RequestMapping("/normal-data")
public class NormalDataController {


    @Autowired
    private NormalDataService normalDataService;

    // 新增或者更新
    @PostMapping
    public boolean save(@RequestBody NormalDataEntity normalData) {
        return normalDataService.saveOrUpdate(normalData);
    }

    @DeleteMapping("/{id}")

    public Boolean delete(@PathVariable Integer id) {
        return normalDataService.removeById(id);
    }

    @PostMapping("/del/batch")
    public boolean deleteBatch(@RequestBody List<Integer> ids) {
        return normalDataService.removeByIds(ids);
    }

    @GetMapping
    public List<NormalDataEntity> findAll() {
        return normalDataService.list();
    }

    @GetMapping("/{id}")
    public NormalDataEntity findOne(@PathVariable Integer id) {
        return normalDataService.getById(id);
    }

    @GetMapping("/page")

    public Page<NormalDataEntity> findPage(@RequestParam Integer pageNum,
                                           @RequestParam Integer pageSize) {
        QueryWrapper<NormalDataEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return normalDataService.page(new Page<>(pageNum, pageSize), queryWrapper);
    }

}

